package com.example.mystore.controller;


import com.example.mystore.model.Trolley;
import com.example.mystore.model.dto.TrolleyDto;
import com.example.mystore.service.TrolleyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/trolleys")
public class TrolleyController {

    private final TrolleyService trolleyService;

    @Autowired
    public TrolleyController(TrolleyService trolleyService) {
        this.trolleyService = trolleyService;
    }

    @PostMapping("/add")
    public void addTrolley(@RequestBody Trolley trolley) {
        trolleyService.addTrolley(trolley);
    }

    @GetMapping("list")
    public ResponseEntity<List<TrolleyDto>> list(Integer id) {
        return ResponseEntity.ok(trolleyService.listById(id));
    }

    @PutMapping("changeQuantity")
    public void changeQuantity(Integer id, Integer quantity) {
        trolleyService.changeQuantity(id, quantity);
    }

    @DeleteMapping("delete")
    public void delete(Integer id) {
        trolleyService.deleteById(id);
    }

    @PostMapping("clear")
    public void clear(Integer id) {
        trolleyService.clearById(id);
    }

}